package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.configuration.domain.MgServicePriceConf;
import com.ruoyi.configuration.service.IMgServicePriceConfService;

import io.swagger.annotations.ApiOperation;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务价格配置Controller
 * 
 * @author ruoyi
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/configuration/serviceprice")
public class MgServicePriceConfController extends BaseController
{
    @Autowired
    private IMgServicePriceConfService mgServicePriceConfService;

    /**
     * 查询服务价格配置列表
     * 剪辑、特效、影视产业园关联产业
     */
    @PreAuthorize("@ss.hasPermi('configuration:serviceprice:list')")
    @GetMapping("/list")
    public TableDataInfo list(MgServicePriceConf mgServicePriceConf)
    {
        startPage();
        List<MgServicePriceConf> list = mgServicePriceConfService.selectMgServicePriceConfList(mgServicePriceConf);
        return getDataTable(list);
    }

    /**
     * 导出服务价格配置列表
     */
    @PreAuthorize("@ss.hasPermi('configuration:serviceprice:export')")
    @Log(title = "服务价格配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MgServicePriceConf mgServicePriceConf)
    {
        List<MgServicePriceConf> list = mgServicePriceConfService.selectMgServicePriceConfList(mgServicePriceConf);
        ExcelUtil<MgServicePriceConf> util = new ExcelUtil<MgServicePriceConf>(MgServicePriceConf.class);
        util.exportExcel(response, list, "服务价格配置数据");
    }

    /**
     * 获取服务价格配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('configuration:serviceprice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mgServicePriceConfService.selectMgServicePriceConfById(id));
    }

    /**
     * 新增服务价格配置
     */
    @PreAuthorize("@ss.hasPermi('configuration:serviceprice:add')")
    @Log(title = "服务价格配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增服务价格配置", tags = {"新增服务价格配置"})
    public AjaxResult add(@RequestBody MgServicePriceConf mgServicePriceConf)
    {
    	
        int insertMgServicePriceConf = mgServicePriceConfService.insertMgServicePriceConf(mgServicePriceConf);
		
        if (-1 == insertMgServicePriceConf) {
        	return error("服务类型不能为空");
        }
        
        if (-2 == insertMgServicePriceConf) {
        	return error("服务价格不能为空");
        }
        
        if (-3 == insertMgServicePriceConf) {
        	return error("服务价格类型已存在");
        }
        
        
        return toAjax(insertMgServicePriceConf);
    }

    /**
     * 修改服务价格配置
     */
    @PreAuthorize("@ss.hasPermi('configuration:serviceprice:edit')")
    @Log(title = "服务价格配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MgServicePriceConf mgServicePriceConf)
    {
        return toAjax(mgServicePriceConfService.updateMgServicePriceConf(mgServicePriceConf));
    }

    /**
     * 删除服务价格配置
     */
    @PreAuthorize("@ss.hasPermi('configuration:serviceprice:remove')")
    @Log(title = "服务价格配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mgServicePriceConfService.deleteMgServicePriceConfByIds(ids));
    }
}
